package sort.algorithm;

import sort.record.Record;
import sort.record.Records;

/**
 * @author masaru-gotou
 *
 */
public class BubbleSort extends Sorter {
	@Override
	public Records sort(Records records) {
		for (int i = 0; i < records.size(); i++) {
			for (int j = 1; j < records.size()-i; j++) {
				if ( records.get(j).getKey() < records.get(j-1).getKey() ) {
					Record tmp = new Record(records.get(j));
					records.set(j, records.get(j-1));
					records.set(j-1, tmp);
					setChanged();
					notifyObservers(records);
				}
			}
		}
		return records;
	}

	@Override
	public String getName() {
		return "Bubble Sort";
	}
}
